package com.jy.rhin.infra.cda.dao.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jy.rhin.facade.cda.dto.ReqDto;
import com.jy.rhin.infra.cda.dao.MenZhenZhaiYaoDao;
import com.jy.rhin.infra.cda.mapper.MenZhenZhaiYaoMapper;
import com.jy.rhin.infra.cda.mzzy.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author dhl
 * @date 2023/2/13
 * @Description
 */
@Service
public class MenZhenZhaiYaoDaoImpl implements MenZhenZhaiYaoDao {
    @Resource
    private MenZhenZhaiYaoMapper menZhenZhaiYaoMapper;


    @Override
    public MenZhenInfoVo queryMenZhenInfo(ReqDto req) {
        QueryWrapper<MenZhenInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("MENZHENJZLSH", req.getJiuZhenLSH());
        return menZhenZhaiYaoMapper.queryMenZhenInfo(queryWrapper);
    }

    @Override
    public List<ShouShuInfoVo> queryShouShuList(ReqDto req) {
        QueryWrapper<ShouShuInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("JIUZHENLSH", req.getJiuZhenLSH());
        queryWrapper.and(wrapper -> wrapper.eq("MENJIZZYBZ", 1).or().eq("MENJIZZYBZ", 2));
        return menZhenZhaiYaoMapper.queryShouShuList(queryWrapper);
    }


    @Override
    public List<JianChaInfoVo> queryJianChaList(ReqDto req) {
        QueryWrapper<JianChaInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("JIUZHENLSH", req.getJiuZhenLSH());
        return menZhenZhaiYaoMapper.queryJianChaList(queryWrapper);
    }


    @Override
    public List<JianYanInfoVo> queryJianYanList(ReqDto req) {
        QueryWrapper<JianChaInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.JIUZHENLSH", req.getJiuZhenLSH());
        return menZhenZhaiYaoMapper.queryJianYanList(queryWrapper);
    }


    @Override
    public List<ZhiLiaoInfoVo> queryZhiLiaoList(ReqDto req) {
        QueryWrapper<ZhiLiaoInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("MENZHENLSH", req.getJiuZhenLSH());
        queryWrapper.and(wrapper -> wrapper.eq("MENZHENZYBZ", 1).or().eq("MENZHENZYBZ", 2));
        return menZhenZhaiYaoMapper.queryZhiLiaoList(queryWrapper);
    }

    @Override
    public List<ZhongYaoInfoVo> queryZhongYaoList(ReqDto req) {
        QueryWrapper<ZhongYaoInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.MENZHENJZLSH", req.getJiuZhenLSH());
        return menZhenZhaiYaoMapper.queryZhongYaoList(queryWrapper);
    }

    @Override
    public List<XiYaoInfoVo> queryXiYaoList(ReqDto req) {
        QueryWrapper<XiYaoInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.MENZHENJZLSH", req.getJiuZhenLSH());
        return menZhenZhaiYaoMapper.queryXiYaoList(queryWrapper);
    }

    @Override
    public List<ZhenDuanInfoVo> queryZhenDuanList(ReqDto req) {
        QueryWrapper<ZhenDuanInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.JIUZHENLSH", req.getJiuZhenLSH());
        queryWrapper.and(wrapper -> wrapper.eq("a.MENJIZZYBZ", 1).or().eq("a.MENJIZZYBZ", 2));
        return menZhenZhaiYaoMapper.queryZhenDuanList(queryWrapper);
    }

    @Override
    public List<FeiYongInfoVo> queryFeiYongList(ReqDto req) {
        QueryWrapper<FeiYongInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.MENZHENJZLSH", req.getJiuZhenLSH());
        queryWrapper.and(wrapper -> wrapper.eq("a.MENJIZZYBZ", 1).or().eq("a.MENJIZZYBZ", 2));
        return menZhenZhaiYaoMapper.queryFeiYongList(queryWrapper);
    }

    @Override
    public ZhuanZhenInfoVo queryZhuanZhenInfo(ReqDto req) {
        QueryWrapper<ZhuanZhenInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YEWUJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("MENZHENLSH", req.getJiuZhenLSH());
        queryWrapper.and(wrapper -> wrapper.eq("MENZHENZYBZ", 1).or().eq("MENZHENZYBZ", 2));
        queryWrapper.orderByDesc("ZHUANZHENRQ").last("limit 1");
        return menZhenZhaiYaoMapper.queryZhuanZhenInfo(queryWrapper);
    }

    @Override
    public XiYiMenZhenBingLiVo queryXiYiMJZBL(ReqDto req) {
        QueryWrapper<XiYiMenZhenBingLiVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUDM", req.getYuanQuID());
        queryWrapper.eq("MENZHENLSH", req.getJiuZhenLSH());
        queryWrapper.orderByDesc("JIUZHENRQSJ").last("limit 1");
        return menZhenZhaiYaoMapper.queryXiYiMJZBL(queryWrapper);
    }

    @Override
    public ZhongYiMenZhenBingLiVo queryZhongYiMJZBL(ReqDto req) {
        QueryWrapper<ZhongYiMenZhenBingLiVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUDM", req.getYuanQuID());
        queryWrapper.eq("MENZHENLSH", req.getJiuZhenLSH());
        queryWrapper.orderByDesc("JIUZHENRQSJ").last("limit 1");
        return menZhenZhaiYaoMapper.queryZhongYiMJZBL(queryWrapper);
    }

}
